/**
 * @author MIAO
 * Created on 2011-10-31
 * For more information, please visit:ismiao.com
 */
package com.ismiao.spring.jdbcTemplate;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class TestPreparedStatement {
	public static void main(String[] args) throws Exception {
		String userID = javax.swing.JOptionPane.showInputDialog(null, "输入客户号");
		String userName = javax.swing.JOptionPane.showInputDialog(null,
				"输入客户姓名");
		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection(
				"jdbc:mysql://localhost:3306/test", "root", "root");
		Statement stat = conn.createStatement();
		String sql = "INSERT INTO users(userID,userName) VALUES(?,?)";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, userID);
		ps.setString(2, userName);
		int i = ps.executeUpdate();
		System.out.println("成功添加" + i + "行");
		stat.close();
		conn.close();
	}
}
